﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mono.Data.Sqlite;

/// <summary>
/// 卡片类型[角色=1/战斗=2/特殊符卡=3]
/// </summary>
public enum CardType
{
    Character=1,
    Battle,
    Special,
    Undefined,
}
/// <summary>
/// 战斗符卡类型[弹幕=0/体术=1]
/// </summary>
public enum BattleType
{
    Dnmaku=0,
    Physical,
    Undefined,
}
/// <summary>
/// 特殊符卡类型[陷阱=1/瞬发道具=2/持续道具=3/状态=4]
/// </summary>
public enum SpecialType
{
    Trap=1,   
    Nitem,
    Bitem,
    State,
    Undefined,
}
/// <summary>
/// 数值类型[华丽度=1/代价=2/战力=3/全部=4]
/// </summary>
public enum NumType
{
    Level=1,
    Cost,
    Battle,
    All,
    Undefined,
}
/// <summary>
/// 角色技能类型[Center=1/Hyper=2/Support=3]
/// </summary>
public enum SkillType
{
    Center=1,
    Hyper,
    Support,
    Undefined,
}
/// <summary>
/// 卡片控制权[玩家1=0/玩家2=1/公用=2/未知=3]
/// </summary>
public enum Owner
{
    Player1=0,
    Player2,
    Public,
    Unknown,
}
/// <summary>
/// 角色技能X
/// </summary>
public struct Skill
{
    public bool IsAvilable;//当前技能有效性
    public SkillType Type;//技能类型
    public string SkillText;//技能描述
    public Skill(SkillType t,string d)
    {
        Type = t;SkillText = d;IsAvilable = true;
    }
}
/// <summary>
/// 特性X
/// </summary>
public struct TEffect
{
    public int GID;//唯一ID
    public string TName;//特姓名
    public string TText;//特性描述
    public TEffect(int g,string tn,string tt)
    {
        GID = g;TName = tn;TText = tt;
    }
}

/// <summary>
/// 基础卡片
/// </summary>
public class Card
{
    public int GID{ get; }//游戏内卡片标识ID
    public Owner Controller { get; }//此卡控制者
    public string Series { get; }//卡片系列
    public int Snum { get; }//卡片系列内编号
    public string Rare { get; }//卡片罕贵度标识
    public string CardName { get; }//卡片名称
    public bool IsFinalCard { get; }//当前卡是否为终符
    public CardType CType { get; }//当前卡片类型[角色/战斗/特殊]
    public string Illust { get; }//当前卡片画师信息
    /// <summary>
    /// 测试用卡初始化
    /// </summary>
    public Card()
    {
        GID =-1;Controller = Owner.Unknown; Series = "Undef";Snum = 0;Rare = "R";Illust = "null";Controller = Owner.Unknown;
        CardName = "Unknown";IsFinalCard = false;CType = CardType.Undefined;
    }
    /// <summary>
    /// 卡数据初始化
    /// </summary>
    /// <param name="gid">游戏内卡片标识ID</param>
    /// <param name="owner">此卡控制者</param>
    /// <param name="series">卡片系列</param>
    /// <param name="snum">卡片系列内编号</param>
    /// <param name="rare">卡片罕贵度标识</param>
    /// <param name="name">卡片名称</param>
    /// <param name="ifc">当前卡是否为终符</param>
    /// <param name="type">当前卡片类型[角色/战斗/特殊]</param>
    /// <param name="ill">当前卡片画师信息</param>
    public Card(int gid,Owner owner,string series,int snum,string rare,string name,bool ifc,CardType type,string ill)
    {
        GID = gid;Controller = owner;Series = series;Snum = snum;Rare = rare;CardName = name;IsFinalCard = ifc;CType = type;Illust = ill;
    }

    /// <summary>
    /// 获取对应卡的卡图的卡名
    /// </summary>
    /// <returns></returns>
    public string[] GetPic()
    {
        string[] temp = new string[2];
        if (CType == CardType.Character)
        {
            temp[0] = Series + "-C-" + Snum;
            temp[1] = Series + "-C-" + Snum+"s";
        }
        return temp;
    }
}

/// <summary>
/// 角色卡
/// </summary>
public class CharacterCard : Card
{
    public string Title { get; }//角色称号
    public string Describe { get; }//角色介绍
    public Skill[] Skills { get; }//角色技能组

    /// <summary>
    /// 测试用卡初始化-角色卡
    /// </summary>
    public CharacterCard():base()
    {
        Title = "Undefined";Describe = "Undefined";
        Skills = new Skill[1];
        Skills[0] = new Skill(SkillType.Undefined, "Udefine");
    }
    /// <summary>
    /// 角色卡数据初始化
    /// </summary>
    /// <param name="gid">游戏内卡片标识ID</param>
    /// <param name="owner">此卡控制者</param>
    /// <param name="series">卡片系列</param>
    /// <param name="snum">卡片系列内编号</param>
    /// <param name="rare">卡片罕贵度标识</param>
    /// <param name="name">卡片名称</param>
    /// <param name="ifc">当前卡是否为终符</param>
    /// <param name="type">当前卡片类型[角色/战斗/特殊]</param>
    /// <param name="ill">当前卡片画师信息</param>
    /// <param name="title">角色称号</param>
    /// <param name="describe">角色介绍</param>
    /// <param name="skills">角色技能组</param>
    public CharacterCard(int gid, Owner owner, string series, int snum, string rare, string name, bool ifc, CardType type, string ill,
        string title,string describe,Skill[] skills)
        :base(gid,owner,series,snum,rare,name,ifc,type,ill)
    {
        Title = title;Describe = describe;Skills = skills;
    }

}
/// <summary>
/// 战斗卡
/// </summary>
public class BattleCard : Card
{
    public int Level { get; }//华丽度
    public int NowLevel { get; set; }//当前华丽度
    public int Cost { get; }//代价
    public int NowCost { get; set; }//当前代价
    public int BattleValue { get; }//战力数值
    public int NowBattleValue { get; set; }//当前战力数值
    public BattleType BType { get; }//战斗类型
    public string EText { get; set; }//效果描述
    public string CText { get; set; }//条件描述
    public List<int> TList { get; set; }//此卡特性列表
    /// <summary>
    /// 测试用卡初始化-战斗卡
    /// </summary>
    public BattleCard() : base()
    {
        Level = NowLevel = 0; Cost = NowCost = 0; BattleValue = NowBattleValue = 0;BType = BattleType.Undefined;EText = "Undefined";
        CText = "Undefined";TList = null;
    }
    /// <summary>
    /// 战斗卡数据初始化
    /// </summary>
    /// <param name="gid">游戏内卡片标识ID</param>
    /// <param name="owner">此卡控制者</param>
    /// <param name="series">卡片系列</param>
    /// <param name="snum">卡片系列内编号</param>
    /// <param name="rare">卡片罕贵度标识</param>
    /// <param name="name">卡片名称</param>
    /// <param name="ifc">当前卡是否为终符</param>
    /// <param name="type">当前卡片类型[角色/战斗/特殊]</param>
    /// <param name="ill">当前卡片画师信息</param>
    /// <param name="level">华丽度</param>
    /// <param name="cost">代价</param>
    /// <param name="bv">战力数值</param>
    /// <param name="btype">战斗类型</param>
    /// <param name="etext">效果描述</param>
    /// <param name="ctext">条件描述</param>
    /// <param name="tlist">当前卡特性列表</param>
    public BattleCard(int gid, Owner owner, string series, int snum, string rare, string name, bool ifc, CardType type, string ill,
        int level, int cost, int bv,BattleType btype,string etext,string ctext, List<int> tlist)
        : base(gid,owner,series,snum,rare,name,ifc,type,ill)
    {
        Level = NowLevel=level;Cost = NowCost=cost;BattleValue = NowBattleValue=bv;BType = btype; EText = etext;CText = ctext;TList = tlist;
    }
    /// <summary>
    /// 检察数值大小[大于返回true]
    /// </summary>
    /// <param name="t">要检查的数据类别</param>
    /// <returns></returns>
    public bool CheckNum(NumType t)
    {
        switch (t)
        {
            case NumType.Level:
                return (NowLevel > Level) ? true : false;
            case NumType.Cost:
                return (NowCost > Cost) ? true : false;
            case NumType.Battle:
                return (NowBattleValue > BattleValue) ? true : false;
            default:
                return false;
        }

    }
    /// <summary>
    /// 重置指定数值的当前数值
    /// </summary>
    /// <param name="t">要重置的数据类别</param>
    /// <returns></returns>
    public bool ResetNum(NumType t)
    {
        switch (t){
            case NumType.Level:
                NowLevel= Level;
                return true;
            case NumType.Cost:
                NowCost = Cost;
                return true;
            case NumType.Battle:
                NowBattleValue = BattleValue;
                return true;
            case NumType.All:
                NowLevel = Level;
                NowCost = Cost;
                NowBattleValue = BattleValue;
                return true;
            default:
                return false;      
        }
    }
}
/// <summary>
/// 特殊卡
/// </summary>
public class SpecialCard : Card
{
    public int Level { get;}//华丽度
    public int NowLevel { get; set; }//当前华丽度
    public int Cost { get;}//代价
    public int NowCost { get; set; }//当前代价
    public string EText { get; set; }//效果描述
    public string CText { get; set; }//条件描述
    public SpecialType SType { get; }//卡的所属分类
    /// <summary>
    /// 测试用卡初始化-战斗卡
    /// </summary>
    public SpecialCard() : base()
    {
        Level = 0;Cost = 0;EText = "Undefined";CText = "Undefined";
        SType = SpecialType.Undefined;
    }
    /// <summary>
    /// 特殊卡数据初始化
    /// </summary>
    /// <param name="gid">游戏内卡片标识ID</param>
    /// <param name="owner">此卡控制者</param>
    /// <param name="series">卡片系列</param>
    /// <param name="snum">卡片系列内编号</param>
    /// <param name="rare">卡片罕贵度标识</param>
    /// <param name="name">卡片名称</param>
    /// <param name="ifc">当前卡是否为终符</param>
    /// <param name="type">当前卡片类型[角色/战斗/特殊]</param>
    /// <param name="ill">当前卡片画师信息</param>
    /// <param name="level">华丽度</param>
    /// <param name="cost">代价</param>
    /// <param name="etext">效果描述</param>
    /// <param name="ctext">条件描述</param>
    /// <param name="stype">卡的所属分类</param>
    public SpecialCard(int gid, Owner owner, string series, int snum, string rare, string name, bool ifc, CardType type, string ill,
        int level, int cost,string etext,string ctext,SpecialType stype)
        : base(gid, owner, series, snum, rare, name, ifc, type, ill)
    {
        Level = level;Cost = cost;EText = etext;CText = ctext;SType = stype;
    }
    /// <summary>
    /// 检察数值大小[大于返回true]
    /// </summary>
    /// <param name="t">要检查的数据类别</param>
    /// <returns></returns>
    public bool CheckNum(NumType t)
    {
        switch (t)
        {
            case NumType.Level:
                return (NowLevel > Level) ? true : false;
            case NumType.Cost:
                return (NowCost > Cost) ? true : false;
            default:
                return false;
        }

    }
    /// <summary>
    /// 重置指定数值的当前数值
    /// </summary>
    /// <param name="t">要重置的数据类别</param>
    /// <returns></returns>
    public bool ResetNum(NumType t)
    {
        switch (t)
        {
            case NumType.Level:
                NowLevel = Level;
                return true;
            case NumType.Cost:
                NowCost = Cost;
                return true;
            case NumType.All:
                NowLevel = Level;
                NowCost = Cost;
                return true;
            default:
                return false;
        }
    }
}